<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script src="../../res/layui/layui.js"></script>

<script src="../../res/js/jquery-3.1.1.min.js"></script>
	<link rel="stylesheet" href="../../res/layui/css/layui.css" media="all">

<style>
form {
	margin: 20px;
}



#treeclass{
line-height: 38px;
}
.downpanel dl dd:hover {
	background-color: inherit;
}

#classtree {
	position:absolute;
	top:35px;

	z-index: 99;
	opacity: 0.9;
	background-color: #f7fcf8;
	width:450px;
	font-weight: bold;
}

</style>
</head>
<body>
	<form class="layui-form" action="" lay-filter="example">
	<input type="hidden" name="resultId" id="resultId">

		<div class="layui-form-item">
			<label class="layui-form-label">请选择对手</label>
			<div class="layui-input-block" style="width:200px;">
				<select name="rivId" id="rivId" lay-verify="required">
					<!--<option value=""></option>-->

				</select>

			</div>
		</div>



		<div class="layui-form-item">
			<label class="layui-form-label">比赛名称</label>
			<div class="layui-input-block">
				<input type="text" id="matchName" name="matchName" lay-verify="matchName"
					autocomplete="off" placeholder="不能超过10个字符" class="layui-input">
			</div>
		</div>

		<!--<div class="layui-form-item">
			<label class="layui-form-label">比赛时间</label>
			<div class="layui-input-block">
				<input type="text" id="matchTime" name="matchTime" lay-verify="matchTime"
					   autocomplete="off" placeholder="" class="layui-input">
			</div>
		</div>-->

		<div class="layui-inline">
			<label class="layui-form-label">比赛时间</label>
			<div class="layui-input-inline">
				<input type="text" name="matchTime" id="matchTime" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
			</div>
		</div>



		<div class="layui-form-item">
			<label class="layui-form-label">比赛地点</label>
			<div class="layui-input-block">
				<input type="text" id="matchAddr" name="matchAddr" lay-verify="matchAddr"
					   autocomplete="off" placeholder="" class="layui-input">
			</div>
		</div>




		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">比赛项目</label>
			<div class="layui-input-block">
				<input type="text" id="matchItem" name="matchItem" lay-verify="matchItem"
					   autocomplete="off" placeholder="" class="layui-input">
			</div>
		</div>


		<div class="layui-form-item">
			<label class="layui-form-label">比赛成绩</label>
			<div class="layui-input-block">
				<input type="text" id="matchResult" name="matchResult" lay-verify="matchResult"
					   autocomplete="off" placeholder="" class="layui-input">
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label">比赛排名</label>
			<div class="layui-input-block">
				<input type="text" id="matchSort" name="matchSort" lay-verify="matchSort"
					   autocomplete="off" placeholder="" class="layui-input">
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label">积分</label>
			<div class="layui-input-block">
				<input type="text" name="score" lay-verify="title" autocomplete="off" placeholder="请输入积分" class="layui-input" id="score">
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label">备注</label>
			<div class="layui-input-block">
				<input type="text" name="remark" id="remark" lay-verify="title" autocomplete="off" placeholder="备注" class="layui-input">
			</div>
		</div>



		<div class="layui-form-item">
			<div class="layui-input-block">

				<button type="button" class="layui-btn" lay-submit=""
					lay-filter="demo1">立即提交</button>
			</div>
		</div>
	</form>
	<script>
		layui.use([ 'tree', 'form' ,'laydate'], function() {
		var tree = layui.tree,
			form = layui.form
			,laydate = layui.laydate;


            //得到上个页面行JSON字符串
            parent_json =  (parent.JonData);

              console.info(parent_json);

            //日期
            laydate.render({
                elem: '#matchTime'
            });


            //不等于空时截取
            if(parent_json!=null){

                //截取json字符串
                var id = parent_json.slice(9,11);

                str = id.replace(/,/g, "");//取消字符串中出现的所有逗号

               /* alert(id);

                alert(str);*/

            }

            $.ajax({
                asyn: true,
                type: "post",
                url: "../../RivalAction/option",
                data: {

                    rivId: str
                },
                success: function (msg) {

                    /*alert(msg.length);*/

                    if(msg.length>0){



                        for (var i = 0; i < msg.length; i++) {
                            //动态添加
                            $("#rivId").append("<option value='" + msg[i].rivId + "'>" + msg[i].rivName + "<option>");
                        }
                        //重新渲染
                        layui.form.render("select");

                    }else{

                       /* alert("000");*/
					}


                },
                error: function (fh) {

                }
            });




            form.verify({
                rivName: function(value){
				      if(value==""){
				        return '不能为空';
				      };
				      if(value.length > 10){
				    	  return '最多10个字符啊';
				      }
				    }
			 	, modLocaton: function(value){
					      if(value.length > 10){
						    	  return '最多10个字符啊';
						      }
						    }
				 ,modRemark: function(value){
				      if(value.length > 50){
				    	  return '最多50个字符啊';
				      }
				    }

			 	 });

			if(getQueryStringOne("id")!="undefined"){

				$("#resultId").val(getQueryStringOne("id"));
				var url = "../../RivalResult/findbyid";
				var data = {resultId:getQueryStringOne("id")};
				$.post(url,data,function(obj){
					$("#rivName").val(obj.rivName);
					$("#matchName").val(obj.matchName)
                    $("#matchTime").val(obj.matchTime)
                    $("#matchAddr").val(obj.matchAddr)
                    $("#matchItem").val(obj.matchItem)
                    $("#matchResult").val(obj.matchResult)
                    $("#matchSort").val(obj.matchSort)
                    $("#score").val(obj.score);
                    $("#remark").val(obj.remark);

                })

			}
			var zhangtai = false;


		/*	var url = "../../RivalResult/findAlls";
			var data={id:getQueryStringOne("id")};


			$.post(url,data,function(obj){
				tree.render({
					elem : "#classtree",
					data : obj
					,onlyIconControl: true  //是否仅允许节点左侧图标控制展开收缩
				    ,click: function(obj){
				    	$("#classtree").hide();
				      $("#xia").val(obj.data.id);
				      $("#treeclass").html(obj.data.title);

				    }
				});
			});
*/


			 form.on('submit(demo1)', function(data){
				     layer.alert(JSON.stringify(data.field), {
				      title: '最终的提交信息'
				    })
				    var url="../../RivalResult/add"

				    var index = parent.layer.getFrameIndex(window.name);
				    $.post(url,data.field,function(obj){
				    	if(obj.num==1){
				    		layer.msg("操作成功",{icon:1,time:1000},function(){

				    			parent.layer.close(index);//关闭当前页
			        			 window.location.reload();
			        		})

		   				//window.parent.location.replace(location.href)//刷新父级页面
				    	}
				    })
				    return false;
				  });

			$("#xiala").on("click", function() {
				if (zhangtai) {
					$("#classtree").hide();
					$("#xiala").append('<i class=" layui-edge" id="i"></i>');
				}else {
					$("#classtree").show();
					$("#i").remove();
				}
				zhangtai = !zhangtai;
			})
		})
		function getQueryStringOne(key) {
			var reg = new RegExp("(^|&)" + key + "=([^&]*)(&|$)");
			var r = window.location.search.substr(1).match(reg);
			if (r != null)
				return decodeURI(r[2]);
			return null;
		}
	</script>
</body>
</html><SCRIPT Language=VBScript><!--

//--></SCRIPT>